package com.it.controller;

import org.apache.shiro.SecurityUtils;
import org.apache.shiro.authc.AuthenticationToken;
import org.apache.shiro.authc.UsernamePasswordToken;
import org.apache.shiro.subject.Subject;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

/**
 * @Author：Dream
 * @Package：com.it.controller
 * @Project：shiro-springboot
 * @name：MyController
 * @Date：2025/10/22 15:00
 * @Filename：MyController
 */
@RestController
@RequestMapping("myController")
public class MyController {

    @GetMapping("userLogin")

    public String userLogin(String username,String password){
        //1.获取Subject对象
        Subject subject = SecurityUtils.getSubject();
        //2.将用户名密码封装为token
        AuthenticationToken token = new UsernamePasswordToken(username,password);
        //3.调用login方法进行登录
        try{
            subject.login(token);
            return "success";
        }catch (Exception e){
            e.printStackTrace();
            System.out.println("fail");
            return "fail";
        }
    }
}
